<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
  <script src="/js/spritejs.js"></script>
  <style>
    html, body {
      width: 100%;
      height: 100%;
      padding: 0;
      margin: 0;
      overflow: hidden;
    }

    #scene-container {
      width: 100%;
      height: 100%;
    }

    #attrs {
      position: absolute;
      top: 0;
      margin-left: 20px;
    }
  </style>
</head>
<body>
  <div id="scene-container"></div>
  <ul id="attrs">
    <li>x: <input name="x" value=""></input></li>
    <li>y: <input name="y" value=""></input></li>
    <li>width: <input name="width" value=""></input></li>
    <li>height: <input name="height" value=""></input></li>
    <li>color: <input name="bgcolor" value="" type="color"></input></li>
  </ul>
  <script>
    (function () {
      const {Scene, Sprite} = spritejs
      const scene = new Scene('#scene-container', {
        viewport: ['auto', 'auto'],
        resolution: [800, 600],
        stickMode: 'width',
      })
      const layer = scene.layer('fglayer')
      const s = new Sprite()
      s.attr({
        anchor: 0.5,
        pos: [400, 300],
        size: [100, 100],
        bgcolor: '#000',
      })
      layer.append(s)
      window.s = s
      document.querySelectorAll('#attrs input').forEach((el) => {
        el.value = s.attr(el.name)
        el.addEventListener('change', ({target}) => {
          s.attr(target.name, target.value)
        })
      })
    }())

  </script>
</body>
</html>